import { DB } from "../db";
import { ServerValues } from "../../../kds-base-define/src/ServerConfig";
import { kdutils } from "kdweb-core/lib/utils";
import { RoomDefine } from "../../../kds-base-define/src/RoomDefine";

let db = DB.get("tds-record","record")
let t_login = "t_login"
async function login(h:string,userID:number,ip:string,type:any,data:any) {
	db.insert(t_login,{
		userID:userID,
		time:kdutils.getMillionSecond(),
		date:kdutils.getFmtMoment("YYYY-MM-DD HH:mm:ss"),
		ip:ip,
		type:type,
		data:data,
	})
	return true 
}

let t_room = "t_room"
async function lobbyRoom(h:string,userID:number,roomID:number,boxCode:string,gameData:RoomDefine.GameData,teaExt:RoomDefine.TeaExtension) {
	db.insert(t_room,{
		userID:userID,
		time:kdutils.getMillionSecond(),
		date:kdutils.getFmtMoment("YYYY-MM-DD HH:mm:ss"),
		roomID:roomID,
		boxCode:boxCode,
		gameData:gameData,
		teaExt:teaExt,
	})
	return true 
}

let t_game_round = "t_game_round"
async function roundStart(h:string,roomID:number) {
	db.insert(t_game_round,{
		roomID:roomID,
		time:kdutils.getMillionSecond(),
		date:kdutils.getFmtMoment("YYYY-MM-DD HH:mm:ss"),
		start:true
	})
	return true 
}

async function roundEnd(h:string,roomID:number,roundEndType:string) {
	db.insert(t_game_round,{
		roomID:roomID,
		time:kdutils.getMillionSecond(),
		date:kdutils.getFmtMoment("YYYY-MM-DD HH:mm:ss"),
		end:true,
		roundEndType:roundEndType == null ? 0 : roundEndType,
	})
	return true 
}

let t_bind_ad = "t_bind_ad"
async function bindAd(h:string,userID:number,adCode:string) {
	db.insert(t_bind_ad,{
		userID:userID,
		adCode:adCode,
		time:kdutils.getMillionSecond(),
		date:kdutils.getFmtMoment("YYYY-MM-DD HH:mm:ss"),
	})
	return true 
}

export let RpcRecord = {
	login:login,
	room:lobbyRoom,
	roundStart:roundStart,
	roundEnd:roundEnd,
	ad:bindAd,
}